package com.ad.admin.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ad.admin.gridviewdemo.R;
import com.ad.admin.utils.Globals;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/4/19.
 */
public class StageAdapter extends BaseAdapter{

    private List<Map<String, Object>> values;
    private Context ctx;

    public StageAdapter(Context ctx, List<Map<String, Object>> values) {
        this.ctx = ctx;
        this.values = values;
    }

    @Override
    public int getCount() {
        return values.size();
    }

    @Override
    public Object getItem(int position) {
        return values.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null) {
            convertView = LayoutInflater.from(ctx).inflate(R.layout.stage_list, null);
            convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Globals.SCREEN_HEIGHT/9));
        }
        TextView stage = (TextView) convertView.findViewById(R.id.stage_num);
        Map<String, Object> map = values.get(position);
        stage.setText(map.get("stageNum").toString());
        stage.getLayoutParams().height = Globals.SCREEN_HEIGHT/9-20;
        if((boolean)map.get("overFlag")) {
            stage.setBackgroundColor(Color.WHITE);
        }else {
            stage.setBackgroundColor(Color.BLACK);
        }
        return convertView;
    }
}
